import config from '../config.js'
export default {
	created: function() {
		console.log('hello from tools mixin!')
	},
	methods: {
		async getLocation() {
			let ipInfo = await this.$request.get('http://ip-api.com/json', {
				baseUrl: '',
				data: {}
			});
			console.log('addr', addr);
			let addr = await this.$request.get('/api/tool/getIpLocation', {
				data: {
					ip: ipInfo.query
				}
			});
			uni.setStorageSync('location', JSON.stringify(addr))
		},
		checkLogin() {
			if (uni.getStorageSync('token') && uni.getStorageSync('userInfo')) {
				return true
			} else {
				return false
			}
		},
		async uploadImg(filePath, extra = {}) {
			let res = await uni.uploadFile({
				url: config.request.baseUrl + this.$requestUrl.UPLOAD_FILE_URL,
				filePath: filePath,
				fileType: "image",
				header: {
					"Content-Type": "multipart/form-data"
				},
				name: "file"
			});
			let data = JSON.parse(res[1].data)
			if (data.code == 0 && data.data) {
				return data.data
			}else{
				return ''
			}
		}
	}
}
